package cn.itcast.bos.service.bc.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.bc.DecidedZoneDao;
import cn.itcast.bos.dao.bc.SubAreaDao;
import cn.itcast.bos.domain.bc.DecidedZone;
import cn.itcast.bos.service.bc.DecidedZoneService;

@Service("decidedZoneService")
@Transactional
public class DecidedZoneServiceImpl implements DecidedZoneService {
	@Autowired
	private DecidedZoneDao decidedZoneDao;
	@Autowired
	private SubAreaDao subAreaDao;

	public void addDecidedZone(DecidedZone model, String[] ids) {
		// 业务 更新两张表 先添加定区 后更新分区 定区 uuid --->修改assigned
		// 1: 添加定区
		decidedZoneDao.save(model);// 代码执行时候 还没有 id
		// decidedZoneDao.saveAndFlush(entity)// uuid
		if (ids != null && ids.length != 0) {
			// 分区表字段更新操作
			for (String id : ids) {
				subAreaDao.assignSubareasToDecidedZone(id, model);
			}
		}

	}

	public Page<DecidedZone> findAll(Pageable pageRequest, Specification<DecidedZone> specification) {
		return decidedZoneDao.findAll(specification, pageRequest);
	}

}
